package dp.gr03.payroll.schedules;

import java.util.GregorianCalendar;

import dp.gr03.payroll.payrollDomain.PaymentSchedule;

public class MonthlySchedule implements PaymentSchedule
{

    @Override
    public boolean isPayDate(GregorianCalendar date)
    {
        return isLastDayOfMonth(date);
    }

    private boolean isLastDayOfMonth(GregorianCalendar date)
    {
        int month1 = date.get(GregorianCalendar.MONTH);
        GregorianCalendar newDate = (GregorianCalendar) date.clone();
        newDate.add(GregorianCalendar.DAY_OF_MONTH, 1);
        int month2 = newDate.get(GregorianCalendar.MONTH);
        
        return month1 != month2;
    }

    @Override
    public GregorianCalendar getPayPeriodStartDate(GregorianCalendar payDate)
    {
        GregorianCalendar startDate = (GregorianCalendar) payDate.clone();
        startDate.set(GregorianCalendar.DAY_OF_MONTH, 1);
        return startDate;
    }
}
